home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MA3.1.1 & CW4.5 / Modifications / *OR* replace these files / UObject.h < prev   
Encoding:
Text File  |  1994-09-17  |  9.9 KB  |  293 lines  |  [TEXT/MPS ]

  1. /*
  2. *    This file has been changed from the original MacApp 3.1.1
  3. *    to support the metrowerks CodeWarrior compilers C/C++ 1.1.1.
  4. *    These changes are known *not* to work with earlier versions
  5. *    of CodeWarrior.  Every attempt though has been made to to keep 
  6. *    this file compatible with other development environments.
  7. *
  8. *    Mark Anderson
  9. *    metrowerks
  10. *    9/16/94
  11. *
  12. */
  13.  
  14. // UObject.h
  15. // Copyright 1984-1994 Apple Computer, Inc. All rights reserved.
  16.  
  17. #ifndef __UOBJECT__
  18. #define __UOBJECT__
  19.  
  20. #ifndef __MACAPPTYPES__
  21. #include <MacAppTypes.h>
  22. #endif
  23.  
  24. #ifndef __UPOINTEROBJECT__
  25. #include <UPointerObject.h>
  26. #endif
  27.  
  28.  
  29. //----------------------------------------------------------------------------------------
  30. // Forward and external class declarations.
  31. //----------------------------------------------------------------------------------------
  32.  
  33. class TObject;
  34. class TStream;
  35. class TDependencySpace;
  36.  
  37. //----------------------------------------------------------------------------------------
  38. // Typedefs
  39. //----------------------------------------------------------------------------------------
  40.  
  41. enum ComparisonResult
  42. {
  43.     kLessThan = -1,
  44.     kEqual = 0,
  45.     kGreaterThan = 1
  46. };
  47.  
  48. typedef long HashValue;
  49.  
  50. //----------------------------------------------------------------------------------------
  51. // TObject: Definition of the system's root object
  52. //----------------------------------------------------------------------------------------
  53.  
  54. DeclareClassDesc(TObject);
  55.  
  56. // ••• JS NEW ••• singleobject + forceclassidfirst + classdescmany
  57.  
  58. #if qMultipleInheritance || qPowerPC || defined(__MWERKS__) || defined(THINK_C) || defined(__SC__)
  59.     #if (qDebug || qSym) && defined(__MWERKS__)
  60.         // make sure CodeWarrior puts fClassID first, not the vtable
  61.         struct ForceClassIDFirst
  62.         {
  63.            ClassID fClassID;
  64.         };
  65.         class TObject : public ForceClassIDFirst
  66.     #else
  67.         // assume the other compilers already put fClassID first (for Jasik)
  68.         class TObject
  69.     #endif
  70. #else
  71.     // for MPW C only and no MI, descend from SingleObject, so vtables are smaller
  72.     class TObject : public SingleObject
  73. #endif
  74. {
  75.     DeclareClass(TObject);
  76.     
  77. public:
  78.  
  79. #if (qDebug || qSym) && !defined(__MWERKS__)
  80.     ClassID fClassID;                // Used to do object validation in debug mode.
  81. #endif
  82.  
  83.     //------------------------------------------------------------------------------------
  84.     // Initializer and I<Method>.
  85.     //------------------------------------------------------------------------------------
  86.  
  87.     TObject();
  88.         // Constructor
  89.  
  90. #if qClassDescMany || (qDebug && THINK_CPLUS)
  91.     virtual ~TObject() {}
  92.         // Virtual Destructor
  93. #endif
  94.  
  95.     void IObject();
  96.         // The ancestral initializer. Should be called in the I<ClassName> chain. i.e.
  97.         // IView -> IEventHandler -> IObject, followed by a called to <ClassName> i.e without
  98.         // the T.
  99.  
  100.     //------------------------------------------------------------------------------------
  101.     // Comparison
  102.     //------------------------------------------------------------------------------------
  103.     
  104.     HashValue Hash() const;
  105.  
  106.     virtual Boolean IsSame(const TObject* theObject) const;
  107.         // Does a handle comparison to determine if the objects are in fact the same object
  108.     
  109.     virtual Boolean IsEqual(const TObject* theObject) const;
  110.         // Must be overridden to be useful.  Default implementation calls IsSame
  111.     
  112.     virtual ComparisonResult CompareObject(const TObject* theObject) const;
  113.         // Compares two objects.
  114.         
  115.     virtual Boolean IsGreaterThan(const TObject* obj) const;
  116.     
  117.     virtual Boolean IsLessThan(const TObject* obj) const;
  118.     
  119.     Boolean operator<(const TObject& obj) const;
  120.         // Calls back to IsLessThan.
  121.     
  122.     Boolean operator>(const TObject& obj) const;
  123.         // Calls back to IsGreaterThan.
  124.     
  125.     Boolean operator>=(const TObject& obj) const;
  126.         // Calls back to IsGreaterThan and IsEqual.
  127.     
  128.     Boolean operator<=(const TObject& obj) const;
  129.         // Calls back to IsLessThan and IsEqual.
  130.     
  131.     Boolean operator ==(const TObject& obj) const;
  132.         // Calls back to IsEqual.
  133.         
  134.     Boolean operator !=(const TObject& obj) const;
  135.     
  136.     //------------------------------------------------------------------------------------
  137.     // Change notification
  138.     //------------------------------------------------------------------------------------
  139.  
  140.     void AddDependent(TObject* dependent);
  141.         // Registers the specified object as a dependent of this object in the global
  142.         // dependency space "gMacAppDependencies", so that it will be notified of changes 
  143.         // in this object.
  144.  
  145.     void RemoveDependent(TObject* dependent);
  146.         // Remove the specified object from the list of dependents of this object in 
  147.         // the global dependency space "gMacAppDependencies".
  148.  
  149.     virtual void Changed(ChangeID theChange, TObject* changedBy);
  150.         // Called to inform dependents of this object in the global dependency space 
  151.         // "gMacAppDependencies" that it has been changed. 
  152.         // "theChange" will often contain a command number.
  153.         // "changedBy" will often contain a command object. 
  154.         // Called often, overridden rarely.
  155.  
  156.     virtual void DoUpdate(ChangeID theChange, 
  157.                                 TObject* changedObject,
  158.                                 TObject* changedBy,
  159.                                 TDependencySpace* dependencySpace);
  160.         // Informs this object that an object on which it is dependent in the global
  161.         // dependency space "gMacAppDependencies" has been changed.
  162.         // Called rarely, overridden often.
  163.  
  164.     virtual TDependencySpace* GetDependencySpace();
  165.         // Returns the default dependency space for storing dependents of this object.
  166.         // Returns gMacAppDependencies.
  167.  
  168.     virtual void SetMark(Boolean state);
  169.         // Intended to mark (state=true) or unmark (state=false) this object. Can be used
  170.         // by dependency spaces that require marking, and overridden by objects that store the
  171.         // mark internally. The MacApp dependency spaces do not use this method. 
  172.  
  173.     virtual Boolean IsMarked();
  174.         // Intended to return true if this object is marked. Can be used
  175.         // by dependency spaces that require marking, and overridden by objects that store the
  176.         // mark internally. The MacApp dependency spaces do not use this method. 
  177.  
  178.     virtual void RemoveAllDependencies();
  179.         // Used by TObject::Free to remove all dependency relations in the global
  180.         // dependency space "gMacAppDependencies" which involve this object, either 
  181.         // as notifier or as dependent.
  182.         
  183.     virtual Boolean RemoveDependenciesOnFree();
  184.         // Default is to return true. This will allow us to optimize certain system
  185.         // objects (like TToolBoxEvents).
  186.  
  187.  
  188.  
  189.     //------------------------------------------------------------------------------------
  190.     // Standard signature support.
  191.     //------------------------------------------------------------------------------------
  192.  
  193.     virtual IDType GetStandardSignature();    // override 
  194.         // Returns this class's standard signature.
  195.  
  196.     //------------------------------------------------------------------------------------
  197.     // Stream I/O protocol support.
  198.     //------------------------------------------------------------------------------------
  199.  
  200.     virtual void ReadFrom(TStream* aStream);
  201.     
  202.     virtual void WriteTo(TStream* aStream);
  203.  
  204.  
  205.     //------------------------------------------------------------------------------------
  206.     // Miscellaneous protocol and support methods.
  207.     //------------------------------------------------------------------------------------
  208.  
  209.     virtual TObject* Clone();
  210.         // Makes a duplicate copy of this. The default calls this->ShallowClone, which
  211.         // makes a literal copy of instance variables but does not attempt to clone owned
  212.         // objects. A subclass which owns other objects should override this to clone the
  213.         // owned objects and data structures as well.
  214.  
  215.     virtual void Free();
  216.         // Called to dispose of an object. Gives object a chance to cleanup after itself.
  217.         // Default simply calls this->ShallowFree, which makes no attempt to free instance
  218.         // variables. Should be overridden by any class which allocates space or owns
  219.         // other objects in its instance variables.. Be sure to call Inherited!
  220.  
  221.     ClassID GetClassID();
  222.         // Returns the class ID of this.
  223.  
  224.     void GetClassName(ClassName& clName);
  225.         // Returns the class name of this.
  226.  
  227.     size_t GetClassSize();
  228.         // Returns the basic instantiation size. i.e. the size in bytes of a newly created
  229.         // object of this class.
  230.  
  231.     const ClassDesc* GetSuperClass();
  232.         // Returns ClassDesc for the immediate superclass. Returns NULL for TObject. If we
  233.         // ever get MI this will have to be an enumerator.
  234.  
  235.     Boolean DescendsFrom(const ClassDesc* classDesc);
  236.         // True if my class is a subclass of the class described by ClassDesc.
  237.         
  238.     Boolean IsSameClass(const ClassDesc* classDesc);
  239.         // True if my class is the same as the class described by ClassDesc.
  240.  
  241.     virtual TObject* ShallowClone();
  242.         // Lowest level method for copying an object; should not be overridden except in
  243.         // very unusual cases. Simply calls HandToHand to copy the object data.
  244.  
  245.     virtual void ShallowFree();
  246.         // Lowest level method for freeing an object; should not be overridden except in
  247.         // very unusual cases. Simply calls delete to free the object.
  248.  
  249.     void SubClassResponsibility();
  250.         // Called from methods that MUST be overridden in a subclass. Signals failure.
  251. };
  252.  
  253.  
  254. typedef TObject* TObjectPtr;
  255.  
  256. typedef TObjectPtr* TObjectPtrPtr;
  257.  
  258. typedef TObjectPtrPtr* TObjectPtrHandle;
  259.  
  260.  
  261. //----------------------------------------------------------------------------------------
  262. // INLINES TObject
  263. //----------------------------------------------------------------------------------------
  264.  
  265. inline Boolean TObject::operator==(const TObject& obj) const 
  266.     return (this->IsEqual(&obj));
  267. }
  268.  
  269. inline Boolean TObject::operator!=(const TObject& obj) const 
  270.     return (this->IsEqual(&obj) == false);
  271. }
  272.  
  273. inline Boolean TObject::operator<(const TObject& obj) const
  274.     return  (this->IsLessThan(&obj));
  275. }
  276. inline Boolean TObject::operator>(const TObject& obj) const
  277.     return (this->IsGreaterThan(&obj));
  278. }
  279. inline Boolean TObject::operator>=(const TObject& obj) const
  280.     return (this->IsGreaterThan(&obj) || this->IsEqual(&obj));
  281. }
  282. inline Boolean TObject::operator<=(const TObject& obj) const
  283.     return (this->IsLessThan(&obj) || this->IsEqual(&obj));
  284. }
  285.  
  286. #endif
  287.